<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <!-- jquery -->
    <script type="text/javascript" th:src="@{/js/jquery.min.js}"></script>
    <!-- bootstrap -->
    <link rel="stylesheet" type="text/css" th:href="@{/bootstrap/css/bootstrap.min.css}" />
    <script type="text/javascript" th:src="@{/bootstrap/js/bootstrap.min.js}"></script>
    <!-- jquery-validator -->
    <script type="text/javascript" th:src="@{/jquery-validation/jquery.validate.min.js}"></script>
    <script type="text/javascript" th:src="@{/jquery-validation/localization/messages_zh.min.js}"></script>
    <!-- layer -->
    <script type="text/javascript" th:src="@{/layer/layer.js}"></script>
    <!-- md5.js -->
    <script type="text/javascript" th:src="@{/js/md5.min.js}"></script>
    <!-- common.js -->
    <script type="text/javascript" th:src="@{/js/common.js}"></script>
</head>
<body>
    <form name="loginForm" id="loginForm" method="post" >
        <h2 style="text-align:center; margin-bottom: 20px">用户登录</h2>
        <div class="form-group">
            <div class="row">
                <label class="form-label col-md-4">请输入手机号码</label>
                <div class="col-md-5">
                    <input id="mobile" name = "mobile" class="form-control" type="text" placeholder="手机号码" required="true"  minlength="11" maxlength="11" />
                </div>
                <div class="col-md-1">
                </div>
            </div>
        </div>
        <div class="form-group">
            <div class="row">
                <label class="form-label col-md-4">请输入密码</label>
                <div class="col-md-5">
                    <input id="password" name="password" class="form-control" type="password"  placeholder="密码" required="true" minlength="6" maxlength="16" />
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-md-5">
                <button class="btn btn-primary btn-block" type="reset" onclick="reset()">重置</button>
            </div>
            <div class="col-md-5">
                <button class="btn btn-primary btn-block" type="submit" onclick="login()">登录</button>
            </div>
        </div>
    </form>
</body>

<script>
    function login(){
        $('#loginForm').validate({
            submitHandler:function(form){
                doLogin();
            }
        });
    }
    function doLogin(){
        g_showLoading();
        var pass = md5(g_passsword_salt.charAt(0)+g_passsword_salt.charAt(2)+$("#password").val()+g_passsword_salt.charAt(5)+g_passsword_salt.charAt(4))
        console.log(g_passsword_salt.charAt(0)+g_passsword_salt.charAt(2)+$("#password").val()+g_passsword_salt.charAt(5)+g_passsword_salt.charAt(4))
        console.log(pass)
        $.ajax({
            type : "POST",
            url :  "/login/do_login",
            data : {
                "mobile":$("#mobile").val(),
                "password":pass
            },
            success : function(data){
                layer.closeAll();
                if(data.code == 0){
                    layer.msg("登录成功",{time: 1000},function(){
                        window.location.href="/goods/to_list";
                    });
                }else{
                    alert(data.msg);
                }
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                layer.closeAll();
                alert("异常");
            }
        });
    }
</script>
</html>